﻿using System;
using System.Collections.Generic;
using Rss;

namespace App_Code.Helpers
{
    /// <summary>
    /// Summary description for Movie
    /// </summary>
    public class Movie
    {
        public string MoviePageLink { get; set; }
        public string Name { get; set; }
        public string ImageLink { get; set; }
        public string Plot { get; set; }
        public List<string> MovieLinks { get; set; }
        public List<RssItem> RssItems { get; set; }
    
        public Movie()
        {
            this.MovieLinks = new List<string>();
            this.RssItems = new List<RssItem>();
        }

        public List<RssItem> GetRssItems(string siteUrl, int pluginId, int mode)
        {
            this.RssItems.Clear();

            var partNum = 1;

            foreach (var movieLink in MovieLinks)
            {
                var rssItem = new RssItem
                {
                    Title = MovieLinks.Count > 1 ? string.Format("{0} - לינק {1}", this.Name, partNum) : this.Name,
                    Description = this.Plot,
                    PubDate = DateTime.Now,
                    Link = new Uri(string.Format("{0}?pluginId={1}&pluginLink={2}&pluginMode={3}", siteUrl, pluginId, Utils.EncodeUrl(movieLink), mode))
                };

                if (!string.IsNullOrEmpty(this.ImageLink))
                {
                    rssItem.Image = new RssImage
                    {
                        Url = new Uri(this.ImageLink),
                        Title = this.Name
                    };
                }
                this.RssItems.Add(rssItem);
                partNum++;
            }
            return this.RssItems;
        }
    }
}